﻿

using HalconDotNet;

namespace CCSFeederCameraUI2.Models
{
    public class HalconEngine
    {
        WorkerEngine hDevEngine1, hDevEngine2;
        string procedureName = string.Empty;
        public HalconEngine()
        {
            hDevEngine1 = new WorkerEngine();
            hDevEngine2 = new WorkerEngine();
        }
        public void Load(string procedurePath, string procedureName2 = "ALMisplaced")
        {
            procedureName = procedureName2;
            //换路径后，外部函数需要重新加载。
            hDevEngine1.RemoveProcedures();
            hDevEngine1.AddProcedure(procedureName2, procedurePath);
            hDevEngine2.RemoveProcedures();
            hDevEngine2.AddProcedure(procedureName2, procedurePath);
        }
        public void Calc1(HObject image_temp, HObject image_new, HObject region, out HObject r_region,
             HTuple maxGrayDark, HTuple minGrayLight, HTuple areaMin, out HTuple r_result)
        {
            hDevEngine1.SetParam(procedureName, "image_temp", image_temp);
            hDevEngine1.SetParam(procedureName, "image_new", image_new);
            hDevEngine1.SetParam(procedureName, "region", region);
            hDevEngine1.SetParam(procedureName, "maxGrayDark", maxGrayDark);
            hDevEngine1.SetParam(procedureName, "minGrayLight", minGrayLight);
            hDevEngine1.SetParam(procedureName, "areaMin", areaMin);
            hDevEngine1.InspectProcedure(procedureName);
            r_result = hDevEngine1.GetParam<HTuple>(procedureName, "r_result");
            r_region = hDevEngine1.GetParam<HObject>(procedureName, "r_region");            
        }
        public void Calc2(HObject image_temp, HObject image_new, HObject region, out HObject r_region,
             HTuple maxGrayDark, HTuple minGrayLight, HTuple areaMin, out HTuple r_result)
        {
            hDevEngine2.SetParam(procedureName, "image_temp", image_temp);
            hDevEngine2.SetParam(procedureName, "image_new", image_new);
            hDevEngine2.SetParam(procedureName, "region", region);
            hDevEngine2.SetParam(procedureName, "maxGrayDark", maxGrayDark);
            hDevEngine2.SetParam(procedureName, "minGrayLight", minGrayLight);
            hDevEngine2.SetParam(procedureName, "areaMin", areaMin);
            hDevEngine2.InspectProcedure(procedureName);
            r_result = hDevEngine2.GetParam<HTuple>(procedureName, "r_result");
            r_region = hDevEngine2.GetParam<HObject>(procedureName, "r_region");
        }
    }
}
